/**
 * File    : ActivityManagerImpl.java
 * Created : 2008-10-10
 * By      : LuHuiguo
 */
package com.luhuiguo.sso.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import com.luhuiguo.sso.dao.ActivityDao;
import com.luhuiguo.sso.entity.Activity;
import com.luhuiguo.sso.entity.AuthAction;
import com.luhuiguo.sso.entity.Site;
import com.luhuiguo.sso.entity.User;
import com.luhuiguo.sso.service.ActivityManager;
import com.luhuiguo.sso.service.SiteManager;

/**
 * @author LuHuiguo
 * @version $Id: ActivityManagerImpl.java 9 2008-10-12 12:51:20Z LuHuiguo $
 * 
 */
public class ActivityManagerImpl implements ActivityManager {

	private ActivityDao activityDao;

	private SiteManager siteManager;	
	
	@Required	
	public void setActivityDao(ActivityDao activityDao) {
		this.activityDao = activityDao;
	}

	@Required
	public void setSiteManager(SiteManager siteManager) {
		this.siteManager = siteManager;
	}
	
	
	@Transactional(readOnly = true)
	@Override
	public Activity getActivity(Long id) {
		return activityDao.get(id);
	}

	@Transactional(readOnly = true)
	@Override
	public List<Activity> getAllActivity(int... rowStartIdxAndCount) {
		return activityDao.findAll(rowStartIdxAndCount);
	}

	@Override
	public void createActivity(Activity activity) {
		activityDao.create(activity);
	}

	@Override
	public void createActivity(User user, Site site, AuthAction action) {
		Activity activity = new Activity(user, site, action);
		createActivity(activity);
	}

	@Override
	public void createActivity(User user, String url, AuthAction action) {
		Site site = siteManager.getSite(url);
		if (site == null) {
			site = new Site(url);
			siteManager.createSite(site);
		}
		createActivity(user, site, action);

	}

	@Override
	public void updateActivity(Activity activity) {
		activityDao.update(activity);
	}

	@Override
	public void deleteActivity(Long id) {
		activityDao.delete(id);
	}

	@Override
	public void deleteActivity(Activity activity) {
		activityDao.delete(activity);

	}

}
